<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <input type="text" placeholder="请输入城市名称" value="郑州" id="city">
        <br>
        <button id="btn">查询</button>
        
        <script src="https://code.jquery.com/jquery-3.1.1.js"></script>
        <script>
            $(function () {
               $("#btn").click(function() {
                  $.ajax({
                      url:"http://apis.baidu.com/apistore/weatherservice/citylist",
                      type:"get",
                      data:{cityname:$("#city").val()},
                      headers:{apikey:"d51be7046037837b1c3f2f006b0a8123"},
                      dataType:'json',
                      success:function(response,status,xhr) {
                          if (response.errMsg === 'success') {
                              var retData = response.retData;
                              for (var i=0;i<retData.length;i++) {
                                  var city_obj = retData[i];
                                  console.log(city_obj.area_id);
                                  console.log(city_obj.name_cn);
                              }
                          }
                      },
                      error:function() {
                          
                      }
                      
                      
                      
                  }); 
               }); 
            });
        
        </script>
        
    </body>
</html>
